//
//  FootCell.m
//  FKGW
//
//  Created by song ce on 2017/2/17.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "FootCell.h"
#import "OSSHelper.h"
@implementation FootCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    //添加左滑手势
    UISwipeGestureRecognizer *swipLeft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swip:)];
    swipLeft.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.moveView addGestureRecognizer:swipLeft];
    //添加右滑手势
    UISwipeGestureRecognizer *swipRight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swip:)];
    swipRight.direction=UISwipeGestureRecognizerDirectionRight;
    [self.moveView addGestureRecognizer:swipRight];
    
    self.xOssProcess =  [NSString stringWithFormat:@"image/resize,m_fill,w_%d,h_%d",80,80];
    // Initialization code
}
- (void)swip:(UISwipeGestureRecognizer *)swipe{
    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
        // 打开
        [self openMenu];
        // 将其他已打开的关闭
        if( self.mySwipeBlock ){
            self.mySwipeBlock();
        }

    }else if (swipe.direction == UISwipeGestureRecognizerDirectionRight){
        // 关闭
        [self closeMenu];
    }
}

- (void)openMenu{
    if (self.isOpen) {
        return;
    }
    [UIView animateWithDuration:0.5 animations:^{
        self.moveView.center = CGPointMake(self.moveView.center.x - 140, self.moveView.center.y);
    }completion:^(BOOL finished) {
        if(finished){
            self.isOpen = YES;
        }
    }];
}

/**关闭左滑菜单*/
-(void)closeMenu
{
    if(!_isOpen)
        return;
    [UIView animateWithDuration:0.5 animations:^{
        self.moveView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.moveView.center.y);
    }completion:^(BOOL finished) {
        if (finished) {
            self.isOpen = NO;
        }
    }];
    
}

-(void)setModel:(FootModel *)model{
    _model = model;
    
    self.goodsNameLabel.text = _model.pName;
    self.priceLabel.text = [NSString stringWithFormat:@"￥ %@",_model.pPrice];
    self.propertyLabel.text = _model.pIntroduce;
//    self.timeLabel.text = _model.pTime;
    [[OSSHelper sharedHelper]OSSDownLoadWithObjectKey:_model.pPic  xOssProcess:self.xOssProcess  downLoadBlock:^(NSData *data) {
        //回主线程
        dispatch_async(dispatch_get_main_queue(), ^{
            //设置评论列表用户头像
            self.goodsImageVeiw.image= [UIImage imageWithData:data];
        });
    }];

}
//删除按钮
- (IBAction)deleteBtn:(UIButton *)sender {
    if(self.myDeleteBlock){
        self.myDeleteBlock();
    }

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
